package com.msconfig.mvp.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.geo.msconfig.R;

import java.util.ArrayList;

// 聊天对话框listview的适配器
public class ReceiveDataAdapter extends BaseAdapter {
    private ArrayList<String> mDatas;
    private Context mContext;

    public ReceiveDataAdapter(ArrayList<String> datas, Context context){
        this.mDatas =datas;
        this.mContext =context;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_activity_listview_item,parent,false);
            holder = new ViewHolder();
            holder.tvData = (TextView)convertView.findViewById(R.id.tv_data);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.tvData.setText(mDatas.get(position));
        return convertView;
    }
    static class ViewHolder{
        TextView tvData;
    }
}


